#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>


using namespace std;
int m;
int fin(int now, int* h)
{
	if (now >= m)
	{
		now = 0;
	}
	if (h[now] == -1)
	{
		return now;

	}
	else
	{
		return fin(now + 1, h);
	}
}
int cou, flag, re, pre;
int findd(int now, int* h, int data)
{
	if ((cou == m + 1) || (re == 1 && pre == now))
	{
		return now;
	}
	re = 1;
	if (now == m)
	{
		now = 0;
	}
	if (h[now] == -1)
	{
		cou++;
		flag = 0;
		return now;

	}
	else if (h[now] == data)
	{
		cou++;
		flag = 1;
		return now;
	}
	else
	{
		cou++;
		return findd(now + 1, h, data);
	}
}
int main()
{

	int t;
	cin >> t;
	while (t--)
	{
		int  n;
		cin >> m >> n;
		int* num = new int[n];
		int* h = new int[m];
		for (int i = 0; i < m; i++)
		{
			h[i] = -1;
		}
		for (int i = 0; i < n; i++)
		{
			cin >> num[i];
		}
		for (int i = 0; i < n; i++)
		{
			int p = num[i] % 11;
			int pp;
			if (num[i] == 0)
			{

				pp = fin(0, h);

			}
			else
			{
				pp = fin(p, h);
			}

			h[pp] = num[i];
		}
		for (int i = 0; i < m; i++)
		{
			if (h[i] != -1)
			{
				cout << h[i] << '*';
			}
			else
			{
				cout << "NULL ";
			}

		}cout <<'#' << endl;
		int k;
		cin >> k;
		while (k--)
		{
			int data;
			cin >> data;
			cou = 0;
			flag = 0;
			re = 0;
			pre = data % 11;
			int now = findd(data % 11, h, data);
			cout << flag << '*' << cou;
			if (flag == 1)
			{
				cout << '*' << now + 1;
			}
			if (k)
			{
				cout <<'#' << endl;
			}
		}
		if (t)cout <<'#' << endl;
	}




	return 0;
}

